import jwt from "jsonwebtoken";

// 假设这是你的 JWT 密钥
const SECRET_KEY = "your_secret_key";

// 定义用户信息的模板
const userInfoTemplate = {
  "id|+1": 1, // 用户ID，初始值为1，每次自增1
  name: "@cname", // 中文名字
  username: "@name", // 中文名字
  email: "@email", // 随机邮箱
  phone: /^1[34578]\d{9}$/, // 随机手机号码
  orgaId: 1,
  orzId: 2,
  orgaName: "组织一",
  orzName: "队一",
};

const getUserList = (size) => {
  let list = [];
  for (let index = 0; index < size; index++) {
    list = list.concat({
      "id|+1": 1, // 用户ID，初始值为1，每次自增1
      name: "@cname", // 中文名字
      username: "@name", // 中文名字
      email: "@email", // 随机邮箱
      phone: /^1[34578]\d{9}$/, // 随机手机号码
      orgaId: 1,
      orzId: 2,
      orgaName: "组织一",
      orzName: "队一",
    });
  }
  return list;
};

// 生成 JWT 令牌的函数
function generateJWTToken() {
  // 这里只是示例，实际使用中可能需要包含更多信息
  return jwt.sign(userInfoTemplate, SECRET_KEY, { expiresIn: "1h" }); // 有效期为1小时
}

export default [
  {
    url: "/api/user/login",
    method: "get",
    response: () => {
      return {
        code: 200,
        data: { ...userInfoTemplate, access_token: generateJWTToken() },
      };
    },
  },
  {
    url: "/api/users/info",
    method: "get",
    response: () => {
      return {
        code: 200,
        data: { ...userInfoTemplate },
      };
    },
  },
  {
    url: "/api/user/permission",
    method: "get",
    response: () => {
      return {
        code: 200,
        data: [
          {
            href: "/home",
            icon: "icon iconfont icon-home",
            operate: "",
            pid: "0",
            id: "1",
            show: true,
            sort: 1,
            title: "首页",
            type: 1,
          },
          {
            href: "/system",
            icon: "icon iconfont icon-user",
            operate: "",
            pid: "0",
            id: "2",
            show: true,
            sort: 1,
            title: "系统管理",
            type: 1,
          },
          {
            href: "/system/users",
            icon: "",
            operate: "",
            pid: "2",
            id: "2-1",
            show: true,
            sort: 4,
            title: "用户管理",
            type: 1,
          },
          {
            href: "/system/roles",
            icon: "",
            operate: "",
            pid: "2",
            id: "2-2",
            show: true,
            sort: 3,
            title: "角色管理",
            type: 1,
          },

          {
            href: "/system/permission",
            icon: "",
            operate: "",
            pid: "2",
            id: "2-2",
            show: true,
            sort: 5,
            title: "权限设置",
            type: 1,
          },
          {
            href: "/system/application",
            icon: "",
            operate: "",
            pid: "2",
            id: "2-3",
            show: true,
            sort: 2,
            title: "应用管理",
            type: 1,
          },
          // {
          //   href: "/system/organization",
          //   icon: "",
          //   operate: "",
          //   pid: "2",
          //   id: "2-4",
          //   show: true,
          //   sort: 1,
          //   title: "组织管理",
          //   type: 1,
          // },
          {
            href: "/designer",
            icon: "",
            operate: "",
            pid: "0",
            id: "3",
            show: true,
            sort: 1,
            title: "设计器管理",
            type: 1,
          },
          {
            href: "/designer/page",
            icon: "",
            operate: "",
            pid: "3",
            id: "3-1",
            show: true,
            sort: 1,
            title: "页面管理",
            type: 1,
          },
          {
            href: "/designer/page/setup",
            icon: "",
            operate: "",
            pid: "3-1",
            id: "3-1-1",
            show: false,
            sort: 1,
            title: "页面设计",
            type: 1,
          },
          {
            href: "/designer/enginee",
            icon: "",
            operate: "",
            pid: "3",
            id: "3-2",
            show: true,
            sort: 1,
            title: "页面设计器",
            type: 1,
          },
          {
            href: "/designer/resourse",
            icon: "",
            operate: "",
            pid: "3",
            id: "3-3",
            show: true,
            sort: 1,
            title: "资源管理",
            type: 1,
          },
          {
            href: "/designer/version",
            icon: "",
            operate: "",
            pid: "3",
            id: "3-4",
            show: true,
            sort: 1,
            title: "版本管理",
            type: 1,
          },
          {
            href: "/designer/depository",
            icon: "",
            operate: "",
            pid: "3",
            id: "3-5",
            show: true,
            sort: 1,
            title: "仓库管理",
            type: 1,
          },
        ],
      };
    },
  },
  {
    url: "/api/user/list",
    method: "get",
    response: (options) => {
      const urlParams = new URLSearchParams(options.url.split("?")[1] || "");
      const list = getUserList(urlParams.get("pageSize"));
      console.log(list, urlParams, "urlParams");
      return {
        code: 200,
        total: 12,
        data: list,
      };
    },
  },
  {
    url: "/api/user/update",
    method: "put",
    response: (options) => {
      const urlParams = new URLSearchParams(options.url.split("?")[1] || "");
      const list = getUserList(urlParams.get("pageSize"));
      return {
        code: 200,
        total: 12,
        data: list,
      };
    },
  },
  {
    url: "/api/user/delete/(d+)",
    method: "delete",
    response: (options) => {
      const urlParams = new URLSearchParams(options.url.split("?")[1] || "");
      const list = getUserList(urlParams.get("pageSize"));
      return {
        code: 200,
        total: 12,
        data: list,
      };
    },
  },
];
